<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/constant.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${path}">
<title>用户管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="RES/ligerui-1.2.3/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="RES/ligerui-1.2.3/lib/ligerUI/skins/Gray2014/css/all.css" rel="stylesheet" type="text/css" />
<link href="RES/ligerui-1.2.3/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="RES/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="RES/ligerui-1.2.3/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="RES/js/m.js" type="text/javascript"></script>
<script type="text/javascript">
	var tgMgr = null;
	$(document).ready(function() {
		//初始化treegrid
		tgMgr = $("#tg").ligerGrid({
			columns : [ {
				display : '用户名',
				name : 'username'
			},{
				display:'密码',
				name:'password'
			}],
			rownumbers : true,
			url : 'system/user/list.do',
			usePager : false,
			height:'100%',
			heightDiff:-6, 
			toolbar : {
				items : [ {
					text : '增加',
					icon : 'add',
					click: function() {
						open("");
					}
				}, {
					line : true
				}, {
					text : '修改',
					icon : 'modify',
					click: modify
				}, {
					line : true
				}, {
					text : '删除',
					icon : 'delete',
					click : toDelete
				} ]
			}
		});
	});
	function reload() {
		tgMgr.reload();
	}
	
	function modify() {
		var rowDatas = tgMgr.getSelectedRows();
		if(rowDatas.length<1) {
			$.ligerDialog.warn('请选择一条记录');
			return false;
		}else if(rowDatas.length>1) {
			$.ligerDialog.warn('每次只能修改一条记录');
			return false;
		}
		open(rowDatas[0].id);
	}
	
	//打开添加或编辑窗口
	function open(id) {
		$.Dialog.open({
            height:300,
            width: 500,
            title : '添加菜单',
            url: 'system/menu/edit.do?id='+id,
            name:'menu_node_dailog',
            buttons:[{
            	text:'确定',
            	cls:'l-dialog-btn-highlight',
            	onclick:function(item,dialog){
            		window.frames['menu_node_dailog'].window.submit();
            	}
            },{
            	text:'关闭',
            	onclick:function(item,dialog) {
            		dialog.close();
            	}
            }]
        })
	}
	function toDelete() {
		var rowDatas = tgMgr.getSelectedRows();
		if(rowDatas.length<1) {
			$.ligerDialog.warn('请选择一条记录');
			return false;
		}else if(rowDatas.length>1) {
			$.ligerDialog.warn('每次只能删除一条记录');
			return false;
		}else {
			if(rowDatas[0].children!=null) {
				var content = "此结点下有子节点，确定删除？";
				$.ligerDialog.confirm(content, function(result) {
					if(!result) return false;
					else $.ajax({
						type : 'POST',
						url : "system/menu/delete.do?id="+rowDatas[0].id,
						success : function(data) {
							tgMgr.reload();
						}
					});
				});
			}else {
				$.ligerDialog.confirm("确定删除？", function(result) {
					if(!result) return false;
					else $.ajax({
						type : 'POST',
						url : "system/menu/delete.do?id="+rowDatas[0].id,
						success : function(data) {
							tgMgr.reload();
						}
					});
				});	
			}
		}
	}
</script>
</head>
<body>
	<div id="toolbar"></div>
	<div id="tg"></div>
</body>
</html>
